package com.ruoyi.web.controller.zhhq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhhq.domain.Carorder;
import com.ruoyi.zhhq.service.ICarorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆订单Controller
 * 
 * @author Anthony Lu
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/zhhq/carorder")
public class CarorderController extends BaseController
{
    @Autowired
    private ICarorderService carorderService;

    /**
     * 查询车辆订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:carorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(Carorder carorder)
    {
        startPage();
        List<Carorder> list = carorderService.selectCarorderList(carorder);
        return getDataTable(list);
    }

    /**
     * 导出车辆订单列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:carorder:export')")
    @Log(title = "车辆订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Carorder carorder)
    {
        List<Carorder> list = carorderService.selectCarorderList(carorder);
        ExcelUtil<Carorder> util = new ExcelUtil<Carorder>(Carorder.class);
        util.exportExcel(response, list, "车辆订单数据");
    }

    /**
     * 获取车辆订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhq:carorder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return AjaxResult.success(carorderService.selectCarorderByOrderId(orderId));
    }

    /**
     * 新增车辆订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:carorder:add')")
    @Log(title = "车辆订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Carorder carorder)
    {
        return toAjax(carorderService.insertCarorder(carorder));
    }

    /**
     * 修改车辆订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:carorder:edit')")
    @Log(title = "车辆订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Carorder carorder)
    {
        return toAjax(carorderService.updateCarorder(carorder));
    }

    /**
     * 删除车辆订单
     */
    @PreAuthorize("@ss.hasPermi('zhhq:carorder:remove')")
    @Log(title = "车辆订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(carorderService.deleteCarorderByOrderIds(orderIds));
    }
}
